package cn.smbms.service.role;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.smbms.dao.role.RoleMapper;
import cn.smbms.pojo.Role;
@Transactional
@Service("roleService")
public class RoleServiceImpl implements RoleService{
	@Autowired
	private RoleMapper roleMapper;
	@Override
	public List<Role> getRoleList(Role role) throws Exception {
		try {
			return roleMapper.getRoleList(role);
		} catch (Exception e) {
			throw e;
			
		}
		
	}

	@Override
	public boolean add(Role role) throws Exception {
		boolean count=false;
		int c=0;
		try {
			roleMapper.add(role);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		if(c>0){
			 count = true;
		}
		return count;
	}

	@Override
	public boolean deleteRoleById(Integer Id) throws Exception {
		boolean count=false;
		int c=0;
		try {
			roleMapper.deletRoleById(Id);
		} catch (Exception e) {
			// TODO: handle exception
		}
		if(c>0){
			 count = true;
		}
		return count;
	}

	@Override
	public boolean modify(Role role) throws Exception {
		boolean count=false;
		int c=0;
		try {
			roleMapper.modify(role);
		} catch (Exception e) {
			// TODO: handle exception
		}
		if(c>0){
			 count = true;
		}
		return count;
	}

	@Override
	public Role getRoleById(Integer id) throws Exception {
		Role role =null;
		try {
			role =roleMapper.getRoleById(id);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

		return role;
	}

	@Override
	public Role roleCodeIsExist(String roleCode) throws Exception {
		Role role =null;
		try {
			role =roleMapper.roleCodeIsExist(roleCode);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return  role;
	}
}
